package algorithm.leetcode

object CheckPossibility {

    fun checkPossibility(nums: IntArray): Boolean {
        var cnt = 0;
        for (i in 0 until nums.size-1) {
            val x = nums[i]
            val y = nums[i + 1]
            if (x > y) {
                cnt++;
                if (cnt > 1) {
                    return false;
                }
                if (i > 0 && y < nums[i - 1]) {
                    nums[i + 1] = x;
                }
            }
        }
        return true;
    }
}

fun main() {
    val ar = intArrayOf(3, 4, 2, 3)
    print(CheckPossibility.checkPossibility(ar))
}